/**
 * File Comment: Ita a GUI
 */
package edu.gatech.oad.project.presentation;
//$codepro.audit.disable
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

import edu.gatech.oad.project.operations.data.Appointment;

/**
 * This class is a panel that allows the user
 * to interact with the GUI to view appointments
 * by doctor.
 * 
 * @author Group 17
 * @version 1
 */
public class SysAdminAppByDoctor extends JPanel {
  
  /**
   * Field driver: holds the Driver connected to the GUI
   */
  private Driver driver;
  
  /**
   * Field lblAppointmentsByDoctor: label
   */
  public JLabel lblAppointmentsByDoctor;
  
  /**
   * Field lblDoctor: label
   */
  public JLabel lblDoctor;
  
  /**
   * Field lblAppointments: label
   */
  public JLabel lblAppointments;
  
  /**
   * Field comboBox: options for doctors
   */
  public JComboBox comboBox;
  
  /**
   * Field list: list of appointments for a given doctor
   */
  public JList list;
  
  /**
   * Field btnViewedit: view/edit button
   */
  public JButton btnViewedit;
  
  /**
   * Field btnBackToHome: back button
   */
  public JButton btnBackToHome;
  
  /**
   * Field doctor: name of the doctor
   */
  private String doctor;
  
  /**
   * Field selected: the Appointment to edit
   */
  private Appointment selected;

 /**
  * Constructor.
  * 
  * @param driver the Driver connected to the GUI
  */
 public SysAdminAppByDoctor(Driver driver) {
   this.driver = driver;
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
  gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
  gridBagLayout.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  setLayout(gridBagLayout);
  
  lblAppointmentsByDoctor = new JLabel("Appointments by Doctor");
  lblAppointmentsByDoctor.setFont(new Font("Lucida Grande", Font.PLAIN, 30));
  GridBagConstraints gbc_lblAppointmentsByDoctor = new GridBagConstraints();
  gbc_lblAppointmentsByDoctor.insets = new Insets(0, 0, 5, 0);
  gbc_lblAppointmentsByDoctor.gridwidth = 8;
  gbc_lblAppointmentsByDoctor.gridx = 0;
  gbc_lblAppointmentsByDoctor.gridy = 0;
  add(lblAppointmentsByDoctor, gbc_lblAppointmentsByDoctor);
  
  lblDoctor = new JLabel("Doctor");
  GridBagConstraints gbc_lblDoctor = new GridBagConstraints();
  gbc_lblDoctor.insets = new Insets(0, 0, 5, 5);
  gbc_lblDoctor.anchor = GridBagConstraints.EAST;
  gbc_lblDoctor.gridx = 1;
  gbc_lblDoctor.gridy = 1;
  add(lblDoctor, gbc_lblDoctor);
  
  String[] doctors = {"Doctor 1","Doctor 2","Doctor 3"};
  comboBox = new JComboBox(doctors);
  comboBox.addActionListener(new ComboBoxListener(this));
  GridBagConstraints gbc_comboBox = new GridBagConstraints();
  gbc_comboBox.gridwidth = 2;
  gbc_comboBox.insets = new Insets(0, 0, 5, 5);
  gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
  gbc_comboBox.gridx = 2;
  gbc_comboBox.gridy = 1;
  add(comboBox, gbc_comboBox);
  
  lblAppointments = new JLabel("Appointments");
  GridBagConstraints gbc_lblAppointments = new GridBagConstraints();
  gbc_lblAppointments.gridwidth = 2;
  gbc_lblAppointments.insets = new Insets(0, 0, 5, 5);
  gbc_lblAppointments.gridx = 0;
  gbc_lblAppointments.gridy = 2;
  add(lblAppointments, gbc_lblAppointments);
  
  list = new JList();
  GridBagConstraints gbc_list = new GridBagConstraints();
  gbc_list.gridheight = 4;
  gbc_list.gridwidth = 2;
  gbc_list.insets = new Insets(0, 0, 5, 5);
  gbc_list.fill = GridBagConstraints.BOTH;
  gbc_list.gridx = 2;
  gbc_list.gridy = 2;
  add(list, gbc_list);
  
  btnViewedit = new JButton("View/Edit");
  btnViewedit.addActionListener(new ButtonListener1(this));
  GridBagConstraints gbc_btnViewedit = new GridBagConstraints();
  gbc_btnViewedit.insets = new Insets(0, 0, 5, 5);
  gbc_btnViewedit.gridx = 2;
  gbc_btnViewedit.gridy = 6;
  add(btnViewedit, gbc_btnViewedit);
  
  btnBackToHome = new JButton("Back to Home");
  btnBackToHome.addActionListener(new ButtonListener2(this));
  GridBagConstraints gbc_btnBackToHome = new GridBagConstraints();
  gbc_btnBackToHome.insets = new Insets(0, 0, 5, 5);
  gbc_btnBackToHome.gridx = 3;
  gbc_btnBackToHome.gridy = 6;
  add(btnBackToHome, gbc_btnBackToHome);
 } // end constructor method
 
 /**
  * Get the Driver.
  * 
  * @return the Driver connected to the GUI
  */
 public Driver getDriver()
 {
   return this.driver;
 } // end getDriver method
 
 /**
  * Set the doctor.
  * 
  * @param the name of the new doctor
  */
 public void setDoctor(String doctor)
 {
   this.doctor = doctor;
   //write code to get calendar and update list
 } // end setDoctor method
 
 /**
  * Get the selected appointment.
  * 
  * @return the Appointment selected
  */
 public Appointment getSelected()
 {
   return this.selected;
 } // end getSelected method
 
 /**
  * This private inner class implements ActionListener for comboBox.
  * 
  * @author Group 17
  * @version 1
  */
 private class ComboBoxListener implements ActionListener
 {
   /**
    * Field apps: the SysAdminAppByDoctor being used
    */
   private SysAdminAppByDoctor apps;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param apps the SysAdminAppByDoctor being used
    */
   private ComboBoxListener(SysAdminAppByDoctor apps)
   {
     this.apps = apps;
     this.driver = apps.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     String doctor = (String)((JComboBox)e.getSource()).getSelectedItem();
     this.apps.setDoctor(doctor);
   } // end actionPerformed method
 } // end ComboBoxListener class

 /**
  * This private inner class implements ActionListener for btnViewedit.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener1 implements ActionListener
 {
   /**
    * Field apps: the SysAdminAppByDoctor being used
    */
   private SysAdminAppByDoctor apps;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param apps the SysAdminAppByDoctor being used
    */
   private ButtonListener1(SysAdminAppByDoctor apps)
   {
     this.apps = apps;
     this.driver = apps.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new SysAdminPatientTR(this.driver,this.apps.getSelected()));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener1 class
 
 /**
  * This private inner class implements ActionListener for btnBackToHome.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener2 implements ActionListener
 {
   /**
    * Field apps: the SysAdminAppByDoctor being used
    */
   private SysAdminAppByDoctor apps;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param apps the SysAdminAppByDoctor being used
    */
   private ButtonListener2(SysAdminAppByDoctor apps)
   {
     this.apps = apps;
     this.driver = apps.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new SysAdminHome(this.driver));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener2 class
} // end SysAdminAppByDoctor class